package com.example.zqh.controller;


import com.example.zqh.model.RespBean;
import com.example.zqh.pojo.Food;
import com.example.zqh.pojo.params.FoodParams;
import com.example.zqh.pojo.params.OneStringOneNumber;
import com.example.zqh.pojo.params.TwoInt;
import com.example.zqh.service.FoodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.security.Principal;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zqh
 * @since 2022-09-10
 */
@RestController
@RequestMapping("/food")
@Api(tags = "食物表的增删改查")
public class FoodController {

    @Autowired
    FoodService foodService;

    /**
      * @Author: zqh
      * @Date:
      * @Description: 店铺添加新菜品
    */
    @ApiOperation(value = "店铺添加新菜品")
    @PostMapping("addNewDishesToTheStore")
    public RespBean addNewDishesToTheStore(@RequestBody FoodParams foodParams, Principal principal)throws IOException{
        return foodService.addNewDishesToTheStore(foodParams,principal);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 下架菜品
    */
    @ApiOperation(value = "下架菜品")
    @DeleteMapping("dishes")
    public RespBean disher(Integer id)throws IOException{
        return foodService.disher(id);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 修改菜品名
    */
    @ApiOperation(value = "修改菜品名(传入菜品id和准备修改菜品的名字)")
    @PostMapping("modifyTheDishName")
    public RespBean modifyTheDishName(@RequestBody OneStringOneNumber oneStringOneNumber)throws IOException{
        return foodService.modifyTheDishName(oneStringOneNumber);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 修改菜品原料
    */
    @ApiOperation(value = "修改菜品原料")
    @PostMapping("modifyTheIngredientsOfDishes")
    public RespBean modifyTheIngredientsOfDishes(@RequestBody OneStringOneNumber oneStringOneNumber)throws IOException{
        return foodService.modifyTheIngredientsOfDishes(oneStringOneNumber);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 修改菜品价格
    */
    @ApiOperation(value = "修改菜品价格")
    @PostMapping("modifyThePriceOfADish")
    public RespBean modifyThePriceOfADish(@RequestBody TwoInt twoInt)throws IOException{
        return foodService.modifyThePriceOfADish(twoInt);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 修改菜品描述
    */
    @ApiOperation(value = "修改菜品描述")
    @PostMapping("modifyTheDescriptionOfTheDish")
    public RespBean modifyTheDescriptionOfTheDish(@RequestBody OneStringOneNumber oneStringOneNumber)throws IOException{
        return foodService.modifyTheDescriptionOfTheDish(oneStringOneNumber);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 修改菜品吃了以后的好处
    */
    @ApiOperation(value = "修改菜品吃了以后的好处")
    @PostMapping("theBenefitsOfModifyingTheDishesAfterEating")
    public RespBean theBenefitsOfModifyingTheDishesAfterEating(@RequestBody OneStringOneNumber oneStringOneNumber)throws IOException{
        return foodService.theBenefitsOfModifyingTheDishesAfterEating(oneStringOneNumber);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 修改菜品图片
    */
    @ApiOperation(value = "修改菜品的图片")
    @PostMapping("modifyPicturesOfDishes")
    public RespBean modifyPicturesOfDishes(@RequestBody OneStringOneNumber oneStringOneNumber)throws IOException{
        return foodService.modifyPicturesOfDishes(oneStringOneNumber);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 查询某个商店菜品的数量
    */
    @ApiOperation(value = "查询某个商店菜品的数量（放行）")
    @GetMapping("getShopFoodNumberByShop_id")
    public RespBean getShopFoodNumberByShop_id(Integer shop_id){
        return foodService.getShopFoodNumberByShop_id(shop_id);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 分页查询菜品
    */
    @ApiOperation(value = "通过店铺id分页查询菜品，（放行）")
    @GetMapping("getFoodsByPage")
    public RespBean getFoodsByPage(Integer shop_id,Integer page,Integer size)throws IOException{
        return foodService.getFoodsByPage(shop_id,page,size);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 通过菜品id，查询某个菜品的信息
    */
    @ApiOperation("通过菜品id查询某个菜品的信息（放行,弃用这个接口）")
    @GetMapping("queryTheInformationOfADishByTheDishId")
    public RespBean queryTheInformationOfADishByTheDishId(Integer id){
        return foodService.queryTheInformationOfADishByTheDishId(id);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 分页查询所有菜品
    */
    @ApiOperation("分页查询所有菜品（放行）")
    @GetMapping("getAllFoodsByPaging")
    public RespBean getAllFoodsByPaging(Integer page,Integer size)throws IOException{
        return foodService.getAllFoodsByPaging(page,size);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 获取所有菜品的数量
    */
    @ApiOperation("获取所有菜品的数量（放行）")
    @GetMapping("getTheQuantityOfAllDishes")
    public RespBean getTheQuantityOfAllDishes(){
        return foodService.getTheQuantityOfAllDishes();
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 通过食物类型，分页查询食物
    */
    @ApiOperation(value = "通过食物种类，分页查询食物(放行)")
    @GetMapping("getFoodsByTypeAndPage")
    public RespBean getFoodsByTypeAndPage(Integer typeId,Integer page,Integer size)throws IOException{
        return foodService.getFoodsByTypeAndPage(typeId,page,size);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 通过食物种类id，获取该种种类的数量
    */
    @ApiOperation("通过食物种类id，获取该种种类的数量(放行）")
    @GetMapping("getNumberByType")
    public RespBean getNumberByType(Integer typeId){
        return foodService.getNumberByType(typeId);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 设置某个菜品为热销菜品
    */
    @ApiOperation("设置某个菜品为热销菜品(需要管理员权限)")
    @PostMapping("setADishAsAPopularDish")
    @PreAuthorize("hasRole('ROLE_admin')")
    public RespBean setADishAsAPopularDish(Integer id)throws IOException{
        return foodService.setADishAsAPopularDish(id);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 把菜品设置为滞销菜品
    */
    @ApiOperation("把菜品设置为滞销菜品(需要管理员权限)")
    @PostMapping("setDishesAsSlowSellingDishes")
    @PreAuthorize("hasRole('ROLE_admin')")
    public RespBean setDishesAsSlowSellingDishes(Integer id)throws IOException{
        return foodService.setDishesAsSlowSellingDishes(id);
    }

    /**
     * @Author: zqh
     * @Date:
     * @Description: 创建food的es数据库
     */
    @PostMapping("createFoodSEsDatabase")
    @ApiOperation("创建song的es数据库，需要管理员权限")
    @PreAuthorize("hasRole('ROLE_admin')")
    public RespBean createFoodSEsDatabase()throws IOException {
        return foodService.createFoodSEsDatabase();
    }

    /**
     * @Author: zqh
     * @Date:
     * @Description: 删除food的es数据库
     */
    @DeleteMapping("deletefoodSEsDatabase")
    @ApiOperation("删除food的es数据库（admin权限）")
    @PreAuthorize("hasRole('ROLE_admin')")
    public RespBean deleteFoodEsDatabase()throws IOException {
        return foodService.deletefoodEsDatabase();
    }

    /**
     * @Author: zqh
     * @Date:
     * @Description: 判断food的es数据库是否存在
     */
    @GetMapping("GetIndex")
    @ApiOperation("判断Food的es数据库是否存在(admin权限)")
    @PreAuthorize("hasRole('ROLE_admin')")
    public RespBean GetIndex()throws IOException {
        return foodService.GetIndex();
    }


    /**
      * @Author: zqh
      * @Date:
      * @Description: song的所有数据库上传es里面
    */
    @PostMapping("allDatabasesOfFoodAreUploadedInEs")
    @ApiOperation("Food的所有数据库上传es里面(admin权限)")
    @PreAuthorize("hasRole('ROLE_admin')")
    public RespBean allDatabasesOfFoodAreUploadedInEs()throws IOException {
        return foodService.allDatabasesOfFoodAreUploadedInEs();
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 搜索引擎
    */
    @GetMapping("searchEngine")
    @ApiOperation(value = "搜索引擎（放行）")
    public RespBean searchEngine(String keyword)throws IOException{
        return foodService.searchEngine(keyword);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 通过名字查询多条菜品
    */
    @GetMapping("searchByname")
    @ApiOperation(value = "通过名字查询多条（放行）")
    public RespBean searchByName(String name)throws IOException{
        return foodService.searchByName(name);
    }

    /**
      * @Author: zqh
      * @Date:
      * @Description: 修改菜品信息接口
    */
    @ApiOperation(value = "管理员修改菜品信息接口")
    @PostMapping("changeFoodByAdmin")
    @PreAuthorize("hasRole('ROLE_admin')")
    public RespBean changeFoodByAdmin(@RequestBody Food food){
        return foodService.changeFoodByAdmin(food);
    }




}

